from socket import *

def get_file_context(file_name):
    try:
        with open('ok\\'+file_name,'rb') as f:
            context=f.read()
            return context
    except:
        print('文件不存在')
# 创建socket
tcp_client_socket = socket(AF_INET, SOCK_STREAM)
server_ip='127.0.0.1'
server_port=(8000)
# 链接服务器
tcp_client_socket.connect((server_ip, server_port))
while True:
    # 提示用户输入数据
    send_data = input("请输入要发送的数据：").lower()
    tcp_client_socket.send(send_data.encode("gbk"))
    if send_data=='no':
        break
    # 接收对方发送过来的数据，最大接收1024个字节
    recvData = tcp_client_socket.recv(1024)
    print('接收到的数据为:', recvData.decode('gbk'))
# # 关闭套接字
tcp_client_socket.close()